#include <iostream>
#include "stock00.h"

void Stock::acquire(const std::string & co, long n, double pr){
    company = co;
    if (n < 0)
    {
        std::cout << "n < 0";
        shares = 0;
    }
    else
        shares = n;
    share_val = pr;
    set_tot();
}

void Stock::buy(long num, double price){
    if (num < 0)
    {
        std::cout << "num < 0";
    }else{
        shares += num;
        share_val = price;
        set_tot();
    }
}

void Stock::sell(long num, double price){
    using std::cout;
    if (num < 0)
    {
        cout << "num < 0";
    }
    else if (num > shares)
    {
        cout << "num > shares";
    }
    else{
        shares -= num;
        share_val = price;
        set_tot();
    }
    
}

void Stock::update(double price){
    share_val = price;
    set_tot();
}

void Stock::show(){
    using namespace std;
    ios_base::fmtflags orig = cout.setf(ios_base::fixed, ios_base::floatfield);
    std::streamsize prec = cout.precision(3);

    cout << company << " " << shares << "shares " << share_val << "$ " << total_val << endl;

    cout.setf(orig, ios_base::floatfield);
    cout.precision(prec);
}